package cac.fenjian.resource.msworkbinbasic.api;

import cac.fenjian.resource.MsWorkbinBasic.dto.MsWorkbinBasicDTO;
import cac.fenjian.resource.common.InvokeService;
import com.cac.dme.adapter.rest.client.RestClient;
import com.cac.dme.adapter.rest.msg.QueryReqBean;
import com.cac.dme.adapter.rest.msg.QueryRespBean;
import com.cac.dme.adapter.rest.msg.ResponseMsg;
import com.cac.dme.adapter.utils.RestClientUtils;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.core.ParameterizedTypeReference;
import org.springframework.stereotype.Component;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Component
@RestController
@Api(tags = "缓存料箱维护外部接口")
@RequestMapping("/msWorkbinapi/")
public class MsWorkbinBasicApi {
    /**
     * 服务编码
     */
    private static final String SERVICE_CODE="xdCommonData";
    private static final String BASE_PATH = "/msworkbin/";

    @Autowired
    private RestClient restClient;
    @Autowired
    private InvokeService invokeService;
    /**
     * 按条件分页查询api
     * @param queryReqBean
     * @return
     */
    @PostMapping("/searchByPage")
    public String searchByPage(@RequestBody QueryReqBean<MsWorkbinBasicDTO> queryReqBean ){
        String url = BASE_PATH + "/searchByPage/v1";
        String result = invokeService.callServicePost(url,SERVICE_CODE,queryReqBean);
        return  result;
    }
    /**
     * 根据条件查询数据
     * @param queryReqBean
     * @return
     */
    @PostMapping("/searchByParams")
    public String searchMsWorkbinByParams(@RequestBody QueryReqBean<MsWorkbinBasicDTO> queryReqBean){
        String url = BASE_PATH + "/searchByParams/v1";
        String result= invokeService.callServicePost(url,SERVICE_CODE,queryReqBean);
        return result;
    }
    @GetMapping("/getMsWorkbin/{id}")
    @ApiOperation(value = "通过主键查询单条记录")
    public MsWorkbinBasicDTO get(@PathVariable  String id){
        String url = BASE_PATH+"/get/v1/"+id;
        ResponseMsg<MsWorkbinBasicDTO> responseMsg = restClient.doGet(SERVICE_CODE, url, new ParameterizedTypeReference<ResponseMsg<MsWorkbinBasicDTO>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
    /**
     * 新增功能API
     * @param msWorkbinBasicDTO
     * @return
     */
    @PostMapping("/insertMsWorkbin")
    @ApiOperation(value = "新增一条数据信息")
    public String insertMsWorkbin(@RequestBody MsWorkbinBasicDTO msWorkbinBasicDTO){
        String url = BASE_PATH +"/save/v1";
        ResponseMsg<String> responseMsg = restClient.doPost(SERVICE_CODE, url, msWorkbinBasicDTO, new ParameterizedTypeReference<ResponseMsg<String>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
    /**
     * 批量新增API
     * @param msWorkbinBasicDTOList 保存对象
     * @return
     */
    @PostMapping("/insertManyMsWorkbin")
    @ApiOperation(value = "批量新增数据")
    public Integer insertMsWorkbinMany(@RequestBody List<MsWorkbinBasicDTO> msWorkbinBasicDTOList){
        String url = BASE_PATH +"/saveMany/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, msWorkbinBasicDTOList, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 删除API
     * @param id id
     * @return
     */
    @PostMapping("/deleteMsWorkbin")
    @ApiOperation(value = "根据主键id删除数据")
    public Integer deleteMsWorkbin(@RequestBody String id){
        String url = BASE_PATH+"/deleteById/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, id, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }

    /**
     * 批量删除apI
     * @param id id
     * @return
     */
    @PostMapping("/deleteManyMsWorkbin")
    @ApiOperation(value = "批量删除数据")
    public Integer deleteManyMsWorkbin(@RequestBody String[] id){
        String url = BASE_PATH+"/deleteByIds/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, id, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }


    @PostMapping("/updateMsWorkbin")
    @ApiOperation(value = "修改单个数据信息")
    public Integer updateMsWorkbin(@RequestBody MsWorkbinBasicDTO msWorkbinBasicDTO){
        String url = BASE_PATH+"/update/v1";
        ResponseMsg<Integer> responseMsg = restClient.doPost(SERVICE_CODE, url, msWorkbinBasicDTO, new ParameterizedTypeReference<ResponseMsg<Integer>>() {
        });
        return RestClientUtils.getResponseBody(responseMsg);
    }
}
